import {
  fetchInformationCollection,
  fetchDirectLive,
  fetchListVideoCourse,
  fetchListVideo,
  fetchListLive,
  fetchListLiveCourse,
  fetchFaceToFace,
  fetchListService
} from '@/services/LiveStreamingServices';
import { fetchListOfflineGoods } from '@/services/CommodityServices';

import {
  fetchListExpressTemplate,

} from '@/services/ExpressTemplateServices';
import {
  fetchListTeacher
} from '@/services/AnsweringServices';
import {
  fetchSearchAdmin
} from '@/services/SystemServices';
import { fetchPageConfig, } from '@/services/WechatPageServices'
export default {
  namespace: 'selectionWindow',
  state: {
    informationCollectionList: { list: [], total: 0 },
    offlineGoodsList: {
      list: [],
      total: 0,
    },
    directLiveList: { list: [], total: 0 },
    videoCourseList: { list: [], total: 0 },
    videoList: { list: [], total: 0 },
    liveList: { list: [], total: 0 },
    liveCourse: { list: [], total: 0 },
    faceToFaceList: { list: [], total: 0 },
    organizationAuthAdminList: { list: [], total: 0 },
    mediaAccountGroupList: { list: [], total: 0 },
    promoterGroupList: {
      list: [],
      total: 0,
    },
    expressTemplateList: {
      list: [],
      total: 0,
    },
    pageConfigList: {},
    teacherList: { list: [], total: 0 },
    serviceList: { list: [], total: 0 },
  },
  effects: {
    *fetchPageConfig({ payload, callback }, { call, put }) {
      const response = yield call(fetchPageConfig, payload);
      if (!response) return;
      const { pageConfigList, total } = response.content;
      yield put({
        type: 'save',
        payload: {
          pageConfigList: {
            list: pageConfigList,
            total,
          },
        },
      });
      callback && callback(pageConfigList)
    },
    *fetchSearchAdmin({ payload, callback }, { call, put }) {
      const response = yield call(fetchSearchAdmin, {
        status: '1',
        ...payload,
      });
      if (!response) return;
      const { authAdminList, total } = response.content;
      callback && callback(authAdminList);
    },
    *fetchListExpressTemplate({ payload, callback }, { call, put }) {
      const response = yield call(fetchListExpressTemplate, payload);
      if (!response) return;
      const {
        content: { expressTemplateList, total },
      } = response;
      yield put({
        type: 'save',
        payload: {
          expressTemplateList: {
            list: expressTemplateList,
            total: total,
          },
        },
      });
      callback && callback(expressTemplateList, total);
    },
    *fetchInformationCollection({ payload, callback }, { call, put }) {
      const response = yield call(fetchInformationCollection, payload);
      if (!response) return;
      const { informationCollectionList, total } = response.content;
      yield put({
        type: 'save',
        payload: {
          informationCollectionList: {
            list: informationCollectionList,
            total,
          },
        },
      });
    },
    *fetchFaceToFace({ payload, callback }, { call, put }) {
      const response = yield call(fetchFaceToFace, payload);
      if (!response) return;
      const { faceToFaceList, total } = response.content;
      yield put({
        type: 'save',
        payload: {
          faceToFaceList: {
            list: faceToFaceList,
            total,
          },
        },
      });
    },

    *fetchListOfflineGoods({ payload, callback }, { call, put }) {
      const response = yield call(fetchListOfflineGoods, payload);
      if (!response) return;
      const {
        content: { goodsOfflineList, total },
      } = response;
      yield put({
        type: 'save',
        payload: {
          offlineGoodsList: {
            list: goodsOfflineList,
            total: total,
          },
        },
      });
      callback && callback();
    },
    *fetchDirectLive({ payload, callback }, { call, put }) {
      const response = yield call(fetchDirectLive, payload);
      if (!response) return;
      const { directLiveList, total } = response.content;
      yield put({
        type: 'save',
        payload: {
          directLiveList: {
            list: directLiveList,
            total,
          },
        },
      });
    },
    *fetchListTeacher({ payload, callback }, { call, put }) {
      const response = yield call(fetchListTeacher, payload);
      if (!response) return;
      const {
        content: { teacherList, total },
      } = response;
      callback && callback(teacherList, total);
    },
    *fetchListVideoCourse({ payload, callback }, { call, put }) {
      const response = yield call(fetchListVideoCourse, payload);
      if (!response) return;
      const { videoCourseList, total } = response.content;
      yield put({
        type: 'save',
        payload: {
          videoCourseList: {
            list: videoCourseList,
            total,
          },
        },
      });
    },
    *fetchListVideo({ payload, callback }, { call, put }) {
      const response = yield call(fetchListVideo, payload);
      if (!response) return;
      const { videoList, total } = response.content;
      yield put({
        type: 'save',
        payload: {
          videoList: {
            list: videoList,
            total,
          },
        },
      });
    },
    *fetchListLive({ payload, callback }, { call, put }) {
      const response = yield call(fetchListLive, payload);
      if (!response) return;
      const { liveList, total } = response.content;
      yield put({
        type: 'save',
        payload: {
          liveList: {
            list: liveList,
            total,
          },
        },
      });
    },
    *fetchListLiveCourse({ payload, callback }, { call, put }) {
      const response = yield call(fetchListLiveCourse, payload);
      if (!response) return;
      const { liveCourseList, total } = response.content;
      yield put({
        type: 'save',
        payload: {
          liveCourse: {
            list: liveCourseList,
            total,
          },
        },
      });
    },
    *fetchListService({ payload, callback }, { call, put }) {
      const response = yield call(fetchListService, payload);
      if (!response) return;
      const { serviceList, total } = response.content;
      yield put({
        type: 'save',
        payload: {
          serviceList: {
            list: serviceList,
            total,
          },
        },
      });
    },
  },
  reducers: {
    save(state, { payload }) {
      return {
        ...state,
        ...payload,
      };
    },
  },
};
